<template>
	<view class="rank-page init-page" :class="themeType==='light'?'bgc-deep-light':'bgc-deep'">
		<!-- #ifndef MP-WEIXIN -->
		<myuni-topbar>
		  <template v-slot:title>
			<text>排行榜</text>
		  </template>
		</myuni-topbar>
		<!-- #endif -->
		<view class="main">
			<myuni-tab :title="titleData" @tabChange="tabChanged">
			</myuni-tab>
			<scroll-view class="scroll-container" scroll-y="true" :scroll-top="top" scroll-with-animation>
				<view class="area-card">
					<view class="card-title" id="guanfang">官方榜单</view>
					<view class="card-content">
						<navigator :url="'/pages/playlist/ranklist?id='+item.id" class="rectangle-card" v-for="(item,index) in this.rankData[0]" :key="item.id" :style="{backgroundColor:bgColorList[index]}">
							<view class="left">
								<text class="title" :style="{color:color[index]}">{{item.name}}</text>
								<image :src="item.coverImgUrl" :lazy-load="true" mode="widthFix"></image>
							</view>
							<view class="right-list">
<!-- 								<view class="song">
									<text class="name">海阔天空</text><text class="singer">-信乐团</text>
								</view> -->
								<view class="song">
									<text class="description">{{item.description}}</text>
								</view>
							</view>
						</navigator>
					</view>
				</view>
				<view class="area-card">
					<view class="card-title">精选榜单</view>
					<view class="card-content flex-content">
						<navigator :url="'/pages/playlist/ranklist?id='+item.id" class="square-card" v-for="item in this.rankData[1]" :key="item.id">
							<image :src="item.coverImgUrl" :lazy-load="true" mode="widthFix"></image>
							<text class="name">{{item.name}}</text>
							<text class="update">{{item.updateFrequency}}</text>
						</navigator>
					</view>
				</view>
				<view class="area-card">
					<view class="card-title">全球榜</view>
					<view class="card-content flex-content">
						<navigator :url="'/pages/playlist/ranklist?id='+item.id" class="square-card" v-for="item in this.rankData[2]" :key="item.id">
							<image :src="item.coverImgUrl" :lazy-load="true" mode="widthFix"></image>
							<text class="name">{{item.name}}</text>
							<text class="update">{{item.updateFrequency}}</text>
						</navigator>
					</view>
				</view>
				<view class="area-card">
					<view class="card-title">曲风榜</view>
					<view class="card-content flex-content">
						<navigator :url="'/pages/playlist/ranklist?id='+item.id" class="square-card" v-for="item in this.rankData[3]" :key="item.id">
							<image :src="item.coverImgUrl" :lazy-load="true" mode="widthFix"></image>
							<text class="name">{{item.name}}</text>
							<text class="update">{{item.updateFrequency}}</text>
						</navigator>
					</view>
				</view>
				<view class="area-card">
					<view class="card-title">特色榜</view>
					<view class="card-content flex-content">
						<navigator :url="'/pages/playlist/ranklist?id='+item.id" class="square-card" v-for="item in this.rankData[4]" :key="item.id">
							<image :src="item.coverImgUrl" :lazy-load="true" mode="widthFix"></image>
							<text class="name">{{item.name}}</text>
							<text class="update">{{item.updateFrequency}}</text>
						</navigator>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
	export default {
		data() {
			return {
				titleData:["官方","精选","全球","曲风","特色"],
				currentTag:0,
				topList:[],
				rankData:[],
				scrollTopList:[],
				top:0,
				bgColorList:['#341922','#182825','#331714','#19232d','#321e15'],
				color:['#e02e74','#219483','#db2622','#2e67b3','#be511f']
			}
		},
		onLoad() {
			this.getTopList()
		},
		mounted() {
			this.scrollTopList=[0,550,852,1300,2200]

		},
		computed:{
			...mapState(['themeType'])
		},
		methods: {
			getTopList(){
				this.request({
					url:'/toplist'
				}).then(res=>{
					this.topList=res.list.map(val=>{
						return {
							coverImgUrl:val.coverImgUrl,
							description:val.description,
							id:val.id,
							name:val.name,
							updateFrequency:val.updateFrequency
						}
					})
					this.$set(this.rankData,0,this.topList.slice(0,5))
					this.$set(this.rankData,1,this.topList.slice(5,11))
					this.$set(this.rankData,2,this.topList.slice(11,19))
					this.$set(this.rankData,3,this.topList.slice(19,26))
					this.$set(this.rankData,4,this.topList.slice(26,35))
				})
			},
			tabChanged(val){
				this.top=this.scrollTopList[val.index]
			}
		}
	}
</script>

<style lang="scss" scoped>
.rank-page{
	padding-bottom: 0;
	.main{
		height: calc(100vh - 50px);
		.scroll-container{
			height: calc(100vh - 100px);
		}
		.area-card{
			margin: 20rpx 0;
			padding: 20rpx;
			border-radius: 20rpx;
			.card-title{
				color: #fff;
			}
			.card-content{}
			.flex-content{
				box-sizing: border-box;
				display: flex;
				flex-wrap: wrap;
			}
		}
		.rectangle-card{
			flex: 1;
			margin: 10rpx 0;
			padding:10rpx 20rpx;
			display: flex;
			// background-color: #fabd01;
			border-radius: 20rpx;
			.left{
				display: flex;
				flex-direction: column;
				.title{
					font-size: 40rpx;
					font-weight: 600;
				}
				image{
					width: 120rpx;
					height: 120rpx;
				}
			}
			.right-list{
				display: flex;
				flex-direction: column;
				justify-content: space-around;
				margin-left: 40rpx;
				.song{
					display: flex;
					font-size: 28rpx;
					.name{
						color: #fff;
					}
					.singer{
						color: #bebebe;
					}
					.description{
						display: -webkit-box;
						 overflow: hidden;
						 -webkit-box-orient: vertical;
						 -webkit-line-clamp: 3;
						 color: #fff;
					}
				}
			}
		}
		.square-card{
			// min-width: 200rpx;
			// min-height: 240rpx;
			padding: 10rpx;
			position: relative;
			display: flex;
			flex-direction: column;
			image{
				width: 200rpx;
				height: 200rpx;
				border-radius: 20rpx;
			}
			.name{
				width: 200rpx;
				text-overflow: ellipsis;
				text-align: center;
				overflow: hidden;
				color: #bebebe;
			}
			.update{
				padding: 0 10rpx;
				position: absolute;
				top: 20rpx;
				right: 20rpx;
				font-size: 24rpx;
				color: #fff;
				background-color: #ccc;
				opacity: .5;
				border-radius: 10rpx;
			}
		}
	}
}
</style>
